#include <cstdio>
#include <cstdlib>

int n, k;
int a[1000001] = {0};
int _min[1000001] = {0};
int _max[1000001] = {0};

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n - k + 1; ++i)
    {
        _min[i] = a[i];
        _max[i] = a[i];
        for (int j = 0; j < k; ++j)
        {
            _min[i] = (_min[i] > a[i + j]) ? a[i + j] : _min[i];
            _max[i] = (_max[i] < a[i + j]) ? a[i + j] : _max[i];
        }
    }
    for (int i = 0; i < n - k + 1; ++i)
        printf("%d ", _min[i]);
    putchar('\n');
    for (int i = 0; i < n - k + 1; ++i)
        printf("%d ", _max[i]);
    putchar('\n');
    return 0;
}